<?php include_once './application/views/sys_admin/common/header.php';  ?>
<!-- admin_main -->
<div class="admin_main">
	<!-- Admin_top end -->
	<?php include_once './application/views/sys_admin/common/user_left.php';  ?>
	<!-- Admin_Left End -->
	<div class="admin_right">
		<div class="admin_right_title">
			<strong>用户管理</strong> >> 会员级别管理
		</div>
		<div class="admin_right_con" style="width: 98%;">
			<a class="addtr" href="javascript:;" onclick="addRank();" >添加一个级别</a>	
			&nbsp;&nbsp;&nbsp;&nbsp;<span>如需新增级别图标，请先将图片通过FTP上传到您服务器项目下的static\credit目录下</span>
			<div class="admin_right_con" style="width: 98%;">
						<table border="0" cellspacing="1" cellpadding="0" bgcolor="#f0f0f0" width="100%">
						  <tbody><tr style="color:#636363;">
							<td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>ID</strong></td>
							<td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>级别名称</strong></td>
							<td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>级别开始积分</strong></td>
							<td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>级别结束积分</strong></td>
							<td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>级别图标名称</strong></td>
							<td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>图标显示</strong></td>
							<td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>操作</strong></td>
						  </tr>
						 	<?php if($list){foreach ($list as $v){?>
						  	 <tr>
							<td height="35" align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $v['id'];?></td>
							<td height="35" align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $v['creidt_rank'];?>级</td>
							<td height="35" align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $v['point1'];?></td>
							<td height="35" align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $v['point2'];?></td>
							<td height="35" align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $v['pic'];?></td>
							<td height="35" align="center" valign="middle" bgcolor="#FFFFFF"><img src="/static/credit/<?php echo $v['pic'];?>"/></td>
							<td height="35" align="center" valign="middle" bgcolor="#FFFFFF"><a href="javascript:changeRank(<?php echo $v['id'];?>);">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:removeRank(<?php echo $v['id'];?>);">删除</a></td>
						  </tr>	
						  <?php }}?>	
						</tbody></table>
					</div>
		</div>
		
	</div>	
<!-- Admin_Right End -->
</div>

<div id="dialog" title="系统提示" style="display:none;">
<div id="msg" style="text-align:center;color:red">&nbsp;</div>
<input type="hidden" name="id" id="id" />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;级别名称：<input type="text" name="creidt_rank" id="creidt_rank" />级 <br /><br />
级别开始积分：<input type="text" name="point1" id="point1" /> <br /><br />
级别结束积分：<input type="text" name="point2" id="point2" /> <br /><br />
级别图标名称：<input type="text" name="pic" id="pic" /> <br /><br />

<div style="text-align:center;">
<input type="button" style="width: 60px; height:24px" value="关闭" onclick="$('#dialog').dialog('close');"/>
<input type="button" style="width: 60px; height:24px" value="修改" onclick="submitRank();" />
</div>
</div>


<div id="adddialog" title="系统提示" style="display:none;">
<div id="addmsg" style="text-align:center;color:red">&nbsp;</div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;级别名称：<input type="text" name="creidt_new_rank" id="creidt_new_rank" />级 <br /><br />
级别开始积分：<input type="text" name="new_point1" id="new_point1" /> <br /><br />
级别结束积分：<input type="text" name="new_point2" id="new_point2" /> <br /><br />
级别图标名称：<input type="text" name="new_pic" id="new_pic" /> <br /><br />

<div style="text-align:center;">
<input type="button" style="width: 60px; height:24px" value="关闭" onclick="$('#adddialog').dialog('close');"/>

<input type="button" style="width: 60px; height:24px" value="修改" onclick="addsubmitRank();" />
</div>
</div>


<script>
function changeRank(id){
	if(id>0){
		$( "#dialog" ).dialog({
			height:250,
			width:500,
			modal:true, //蒙层（弹出会影响页面大小）
			title:'编辑会员级别'
		});
		
		$( "#id").val(id);
		
		$.ajax({
			type: "POST",
			url: "/sys_admin/user/leve_synchronize",
			data: "id="+$("#id").val(),
			success: function(ret){
				$("#creidt_rank").val(ret.msg.creidt_rank);
				$("#point1").val(ret.msg.point1);
				$("#point2").val(ret.msg.point2);
				$("#pic").val(ret.msg.pic);
			},
			dataType: "json"
		});
	}
}

function submitRank(){
	var id = $("#id").val();
	if(id > 0){
		$.ajax({
			type: "POST",
			url: "/sys_admin/user/credit_rank_save",
			data: "act=edit&id="+id+"&creidt_rank="+$("#creidt_rank").val()+"&point1="+$("#point1").val()+"&point2="+$("#point2").val()+"&pic="+$("#pic").val(),
			success: function(ret){
				$("#dialog" ).dialog();
				$("#msg").html(ret.msg);
				setTimeout(function(){
					$("#dialog" ).dialog("close");
				},5000);
				window.location.reload();
			},
			dataType: "json"
		});	
	}
}

function addRank(){
	$( "#adddialog" ).dialog({
		height:250,
		width:500,
		modal:true, //蒙层（弹出会影响页面大小）
		title:'添加会员级别'
	});
}

function addsubmitRank(){
		$.ajax({
			type: "POST",
			url: "/sys_admin/user/credit_rank_save",
			data: "act=add&creidt_rank="+$("#creidt_new_rank").val()+"&point1="+$("#new_point1").val()+"&point2="+$("#new_point2").val()+"&pic="+$("#new_pic").val(),
			success: function(ret){
				$("#adddialog" ).dialog();
				$("#addmsg").html(ret.msg);
				setTimeout(function(){
					$("#adddialog" ).dialog("close");
				},5000);
				window.location.reload();
			},
			dataType: "json"
		});	
}

function removeRank(id){
	if(confirm('你确定要删除?'))
	{
		if(id > 0){
			$.ajax({
				type: "POST",
				url: "/sys_admin/user/credit_rank_save",
				data: "act=delete&id="+id,
				success: function(ret){
					window.location.reload();
				},
				dataType: "json"
			});	
		}	
	}	
}
</script>
<!-- admin_main end -->
</body>
</html>
